package com.spzx.product.api.fallback;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.exception.ServiceException;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.ProductSkuVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestHeader;

/**
 * ClassName: RemoteProductFallbackFactory
 * Description:
 *
 * @Author linz
 * @Creat 2025/3/17 18:43
 * @Version 1.00
 */
//@Component
//由于在org.springframework.boot.autoconfigure.AutoConfiguration.imports中添加了该类，所以不用再配置了
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {

    /**
     * 降级处理
     * @param cause
     * @return
     */
    @Override
    public RemoteProductService create(Throwable cause) {
        return new RemoteProductService() {
            @Override
            public R<ProductSkuVo> getProductSku(Long skuId,String source) {
                cause.printStackTrace();
                return R.fail("获取商品Sku详情失败->"+cause.getMessage());
            }
        };
    }
}
